package com.scraper.articles.web.dao.impl;

import com.scraper.articles.web.dao.RequestDao;
import com.scraper.articles.web.model.Request;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public class RequestDaoImpl extends BaseDao implements RequestDao {

    public void saveRequest(Request request) {
        getSession().merge(request);

    }

    @SuppressWarnings("unchecked")
    public List<Request> listRequests() {

        return getSession().createCriteria(Request.class).list();
    }

    public Request getRequest(Long id) {
        return (Request) getSession().get(Request.class, id);
    }

    public void deleteRequest(Long id) {

        Request request = getRequest(id);

        if (null != request) {
            getSession().delete(request);
        }

    }
}
